<template>
    <nav class="navbar">
      <!-- 左侧 Logo & 导航菜单 -->
      <div class="navbar-left">
        <div class="navbar-brand" @click="goTo('/')">AgentFlow Studio</div>
        <ul class="nav-links">
          <li v-for="item in menuItems" :key="item.path">
            <router-link :to="item.path" active-class="active">{{ item.label }}</router-link>
          </li>
        </ul>
      </div>
  
      <!-- 右侧按钮 & 用户头像 -->
      <div class="navbar-right">
        <button v-if="showButton" @click="handleClick" class="nav-button">
          {{ buttonText }}
        </button>
  
        <!-- 用户头像 & 下拉菜单 -->
        <div class="user-menu">
          <img
            src="https://via.placeholder.com/40"
            alt="User Avatar"
            class="user-avatar"
            @click="toggleDropdown"
          />
          <ul v-if="dropdownOpen" class="dropdown-menu">
            <li @click="goTo('/profile')">个人中心</li>
            <li @click="goTo('/settings')">设置</li>
            <li @click="logout">退出登录</li>
          </ul>
        </div>
      </div>
    </nav>
  </template>
  
  <script setup>
  import { ref, defineProps, defineEmits } from 'vue'
  import { useRouter } from 'vue-router'
  
  const router = useRouter()
  const dropdownOpen = ref(false)
  
  const props = defineProps({
    menuItems: {
      type: Array,
      default: () => [
        { path: '/team', label: '团队' },
        { path: '/projects', label: '项目广场' }
      ]
    },
    showButton: {
      type: Boolean,
      default: false
    },
    buttonText: {
      type: String,
      default: '按钮'
    }
  })
  
  const emit = defineEmits(['buttonClick'])
  
  const handleClick = () => {
    emit('buttonClick')
  }
  
  const goTo = (path) => {
    router.push(path)
    dropdownOpen.value = false // 关闭下拉菜单
  }
  
  const toggleDropdown = () => {
    dropdownOpen.value = !dropdownOpen.value
  }
  
  const logout = () => {
    alert('已退出登录') // 这里可以改成实际的登出逻辑
    dropdownOpen.value = false
  }
  </script>
  
  <style scoped>
  /* 基础样式 */
  .navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: #282c34;
    color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  }
  
  /* 左侧导航 */
  .navbar-left {
    display: flex;
    align-items: center;
  }
  
  .navbar-brand {
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    margin-right: 20px;
  }
  
  .nav-links {
    list-style: none;
    display: flex;
    gap: 15px;
  }
  
  .nav-links li {
    display: inline;
  }
  
  .nav-links a {
    color: white;
    text-decoration: none;
    font-size: 1rem;
    padding: 5px 10px;
    border-radius: 5px;
  }
  
  .nav-links a.active {
    background-color: #4CAF50;
  }
  
  /* 右侧区域 */
  .navbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
  }
  
  /* 按钮 */
  .nav-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 1rem;
    border-radius: 5px;
  }
  
  .nav-button:hover {
    background-color: #45a049;
  }
  
  /* 用户头像 & 下拉菜单 */
  .user-menu {
    position: relative;
  }
  
  .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
  }
  
  .dropdown-menu {
    position: absolute;
    right: 0;
    top: 50px;
    background: white;
    color: black;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    list-style: none;
    padding: 10px 0;
    width: 150px;
  }
  
  .dropdown-menu li {
    padding: 10px;
    cursor: pointer;
  }
  
  .dropdown-menu li:hover {
    background-color: #f0f0f0;
  }
  </style>
  